﻿using System.Text.RegularExpressions;

namespace HQS.TokenInterpolation
{
    internal static class StringUtil
    {
        private const string EscapeRegExpPattern = @"\\[{}']*";

        /// <summary>
        ///     A case insensitive replace function.
        /// </summary>
        /// <param name="originalString">The string to examine.(HayStack)</param>
        /// <param name="oldValue">The value to replace.(Needle)</param>
        /// <param name="newValue">The new value to be inserted</param>
        /// <returns>A string</returns>
        public static string CaseInsenstiveReplace(string originalString, string oldValue, string newValue)
        {
            var regEx = new Regex(oldValue,
                RegexOptions.IgnoreCase | RegexOptions.Multiline);
            return regEx.Replace(originalString, newValue);
        }

        public static bool ToBoolean(string value)
        {
            return value != null && (value.Trim().ToLower() == "true" || value.Trim() == "1");
        }

        public static string Between(string source, int fromIndex, int endIndex)
        {
            return source.Substring(fromIndex, (endIndex - fromIndex) + 1);
        }
    }
}